package com.example.newhbsj;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.example.newhbsj.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.text.style.URLSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class RegisterActivity extends Activity{
	
	
	private ImageButton exit;
	private Button nextstep;
	private TextView link;
	private EditText tel;
	private CheckBox check;
	public static String tel1;
	
	public static RegisterActivity activity;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_register);
		activity=this;
		exit=(ImageButton) findViewById(R.id.exit);
		nextstep=(Button) findViewById(R.id.nextstep);
		link=(TextView) findViewById(R.id.link);
		tel=(EditText) findViewById(R.id.newtel);
		check=(CheckBox) findViewById(R.id.check);
		
		SpannableString sp=new SpannableString("已阅读《货比三家用户协议》");
		sp.setSpan(new URLSpan("https://www.baidu.com/"), 3, 13, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		 sp.setSpan(new ForegroundColorSpan(Color.BLUE), 3,13,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);    
		 link.setText(sp);
		 link.setMovementMethod(LinkMovementMethod.getInstance());    
		 
		 
		 
		exit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			finish();
			Intent i=new Intent(RegisterActivity.this,LogonActivity.class);
			startActivity(i);
			}
		});
		
		nextstep.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(check.isChecked()){
					tel1=tel.getText().toString();
					if(isPhone(tel1)){
						Intent i=new Intent(RegisterActivity.this,SetpasswdActivity.class);
						startActivity(i);	
						finish();
					}else{
						Toast.makeText(RegisterActivity.this, "请输入11位手机号",Toast.LENGTH_SHORT ).show();
					}
				}
			}
		});
		
		
			findViewById(R.id.regi).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				switch (v.getId()) {  
			    case R.id.regi:  
			         InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);  
			         imm.hideSoftInputFromWindow(v.getWindowToken(), 0);  
			        break;  
			}
		}
		});
	}
	private boolean isPhone(String inputText) {
        Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,3,5-9]))\\d{8}$");
        Matcher m = p.matcher(inputText);
        return m.matches();
    }


}
